package com.btpj.shop.dto;


import com.btpj.shop.entity.Role;
import com.btpj.shop.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

@ApiModel(value = "UserDto", description = "用户信息封装对象")
@Data
public class UserDto implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("编号")
    private Long id;

    @ApiModelProperty("用户名")
    private String name;

    @ApiModelProperty("昵称")
    private String nickName;

    @ApiModelProperty("用户头像链接")
    private String photo;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("用户角色")
    private List<Role> roles;

    /**
     * 将实体转化为接口需要的DTO结构
     *
     * @param user User
     * @return UserDto
     */
    public static UserDto entity2Dto(User user) {
        UserDto userDto = new UserDto();
        if (user != null) {
            BeanUtils.copyProperties(user, userDto);
        }
        return userDto;
    }
}
